/************************************************
 * Copyright (c) 2007 ~ 2009, 
 * All rights reserved.
 * Version   : 1.0
 * Author    : lengsh@alibaba-inc.com 
 * Date      : 2009.1.2
 ************************************************/

#ifndef   __HERON_MYSQLSTORAGE_H___
#define   __HERON_MYSQLSTORAGE_H___

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <syslog.h>
#include <signal.h>
#include <unistd.h>
#include <mysql.h>
#include <glib.h>
#include <viva.h>
#include "IStorage.h"
using namespace std;

class MySQLStorage : public  IStorage
{
	public:
		MySQLStorage(){
		}
		virtual ~MySQLStorage(){   
		}
		virtual bool Initialize(const char *conf) ;
		virtual int Read(int ihash, GHashTable *kv, char **wbuf, unsigned &wsize, unsigned &wbytes);
		virtual int Atom(int ihash, GHashTable *kv, char **wbuf, unsigned &wsize, unsigned &wbytes);
		virtual int Write(int ihash, GHashTable *kv);
		virtual int Delete(int ihash, GHashTable *kv);

	protected:
                Viva *m_pTx;
                bool m_bWrite2DB;

};

extern "C" IStorage* create_storage( const char *config);
extern "C" void destroy_storage(MySQLStorage *obj);

#endif  // __HERON_MYSQLSTORAGE_H___
